from api.login_api import loginApi
from utils.RequestUtils import Request
from utils.log import LoggerUtils


class orderApi:

    def __init__(self):
        self.log = LoggerUtils().logger()
        self.request = Request()

    def all_order_page(self, pageSize=10, pageNum=1):
        """
        全部订单分页查询接口
        :param pageSize: 页数长度：默认最短10，20,30,40,50,100
        :param pageNum:默认页数从第一页开始，1
        :return:返回响应结果
        """
        url = 'https://stage.geer2.com/ym/order/page'
        params = {
            "orderType": "all",
            "pageNum": pageNum,
            "pageSize": pageSize,
            "isRefundIgnore": 1
        }
        headers = {
            "Authorization": "Bearer" + " " + loginApi().login()
        }
        response = self.request.get(url=url,params=params,headers=headers)
        return response

    def all_order_search(self,orderCode=None,pageSize=10, pageNum=1,companyId=319,companyIdName="柒美财润店"):
        """
        条件查询全部订单
        :param orderCode: 订单搜索
        :param pageSize: 页数长度：默认最短10，20,30,40,50,100
        :param pageNum:默认页数从第一页开始，1
        :param companyId: 门店ID
        :param companyIdName: 门店名称
        :return: 返回响应结果
        """
        url = "https://stage.geer2.com/ym/order/page"
        params = {
            "orderType": "all",
            "pageNum": pageNum,
            "pageSize": pageSize,
            "isRefundIgnore": 1,
            "companyId":companyId,
            "orderCode": orderCode,
            "$companyId":companyIdName
        }
        headers = {
            "Authorization": "Bearer" + " " + loginApi().login()
        }
        response = self.request.get(url=url,params=params,headers=headers)
        return response

    def order_details(self,orderId):
        """
        订单详情接口
        :param orderId:订单ID
        :return:
        """
        url = "https://stage.geer2.com/ym/order/"+orderId
        headers = {
            "Authorization": "Bearer" + " " + loginApi().login()
        }
        response = self.request.get(url=url,headers=headers)
        return response




if __name__ == '__main__':
    # orderApi().order_details('20803')
    orderApi().all_order_search(orderCode='FWDD20240521135615315')
